package com.minarto.display.ui.list {
	import scaleform.clik.core.CLIK;
	import com.minarto.utils.MathX;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	/**
	 * ...
	 * @author minarto
	 */
	public class VScrollListContainer extends ListContainer implements IVScrollContainer
	{
		private var _scrollRate:Number = 0;
		public function getScrollRate():Number {
			return	_scrollRate;
		}
		public function setVScrollRate($rate:Number = 0):void {
			var r:Rectangle, sr:Rectangle, v:Boolean;
			
			v = visible;
			visible = false;
			$rate = isNaN($rate) ? _scrollRate : $rate;
			
			r = MathX.RECTANGLE;
			sr = scrollRect;
			
			r.x = sr.x;
			r.y = sr.y;
			r.width = sr.width;
			r.height = sr.height;
			
			if ($rate <= 0) {
				_scrollRate = 0;
				r.y = 0;
			}
			else if ($rate < 1) {
				_scrollRate = $rate;
				r.y = (height - r.height) * $rate;
			}
			else {
				_scrollRate = 1;
				r.y = height - r.height;
			}
			
			scrollRect = r;
			visible = v;
		}
		
		
		public function setScrollRect($x:Number=0, $y:Number=0, $width:Number=0, $height:Number=0):void {
			var r:Rectangle, v:Boolean;
			
			v = visible;
			visible = false;
			
			r = MathX.RECTANGLE;
			r.x = $x;
			r.y = $y;
			r.width = $width;
			r.height = $height;
			
			scrollRect = r;
			visible = v;
		}
		
		public function autoReSize($auto:Boolean):void {
			CLIK.stage.addEventListener(Event.ENTER_FRAME, _checkSize);
		}
		
		
		private var _height:Number;
		
		private function _checkSize($e:Event):void {
			var h:Number, v:Boolean;
			
			h = height;
			if (_height == h) {
			}
			else {
				v = visible;
				visible = false;
				setVScrollRate(_scrollRate);
				visible = v;
				_height = h;
			}
		}
	}
}